<cfscript>    
    view = createObject("component", session.rootDir & ".views.layout");
    if( Session.Auth EQ True and (Session.strAuthType EQ Session.MANAGERS or Session.strAuthType EQ Session.IT or Session.strAuthType EQ Session.HR) ){
		view.init("Step 6:  Facilities - Termination",
			"/jquery/ui-1.8.5/jquery-ui.min.js,/jquery/plugins/scrollTo/jquery.scrollTo-1.4.2-min.js, /" & session.rootDir & "/static/js/SCF/Step6-AccessControlTerm.js",
			"/jquery/ui-1.8.5/themes/cupertino/jquery-ui.css","Home",main, "Termination");
    }else{
        view.init("Denied","","","Home","Denied");
    }    
    view.html();
</cfscript>

<cffunction name="main" access="public" output="true" returntype="any">
    <cfparam default="-1" name="URL.TermReqID" />
    <cfscript>
        import models.*;
        FormAction = '/' & session.rootDir & '/controller/SubmitHandlerTermination.cfm?SCFStep6=update';
        FormCompleteAction = '/' & session.rootDir & '/termination/status.cfm'; //when submit is all done.
        KronosQueries = CreateObject("component", session.rootDir & ".DatabaseQueries.Kronos");     
        if( isDefined('URL.TermReqID') AND URL.TermReqID NEQ -1 ){
            StepActions = ORMExecuteQuery("FROM StepActions WHERE TermReqID = ? AND StepsID = 27", [URL.TermReqID] );
        }else{
            StepActions = ORMExecuteQuery("FROM StepActions WHERE StepsID = 27 AND ActTimeStamp IS NULL AND TermReqID IS NOT NULL");
            URL.TermReqID = -1;
        }
    </cfscript>
    
    
    <cfoutput> 
    <h1 class="title">Step 6: Facilities - Termination</h1>
        <div class="entry">    
            Welcome, #Session.EmpInfo.FirstName# #Session.EmpInfo.LastName#.  
            In this step, we'll confirm that the terminated individuals 
            have indeed been terminated in the facilities system.  
            This is the list of employees that are staged for 
            termination in Facilities.  After successfully terminating 
            the employee, please place a check in the box next to their 
            name and hit the "Complete" button.  This will update their 
            EPAR record and remove them from the Facilities queue.
            <br /><br /> 

            <cfform name="frmStep6" method="post" action="#FormAction#">
                <table width=100%>
                    <tr>
                        <td><cfinput type="checkbox" name="CheckAll" value="1"></td>
                        <td align="left"><strong>Name</strong></td>
                        <td align="left"><strong>Term Date</strong></td>
                        <td align="left"><strong>BadgeID</strong></td>
                    </tr>
    
                    <cfloop from="1" to="#ArrayLen(StepActions)#" index="i">

                    	<cfset TermRequest = entityLoadByPK("TerminationRequests", StepActions[i].getTermReqID()) />
                        <cfset Employee = KronosQueries.funcGetAllEmployees(TermRequest.getRosettaID()) />
                        <cfset Badge = EntityLoad("Badges", {RosettaID = Employee.RosettaID} ) />

                        <cfif Employee.RecordCount NEQ 0>
                            <tbody id="#StepActions[i].getStepActionsID()#" class="AccessControlTerm">
                                <tr>
                                    <td nowrap="nowrap"><cfinput type="checkbox" name="AccessControlTerm" value="1" class="terms"></td>
                                    <td nowrap="nowrap">#Employee.FirstName# #Employee.LastName#</td>
                                    <td >HR: #DateFormat(TermRequest.getSysTermDate(),'mm/dd/yy')#</td>
                                    <td>
                                        <cfloop from="1" to="#ArrayLen(Badge)#" index="i" >
                                            #Badge[i].getBadgeNumber()# #(i EQ ArrayLen(Badge) ? "" : ',')#
                                        </cfloop>                                    
                                    </td>
                                    <cfinput type="hidden" name="TermReqID" value="#TermRequest.getTerminationRequestsID()#" />
                                    <cfinput type="hidden" name="RosettaID" value="#Employee.RosettaID#" />
                                </tr>
                            </tbody>
                        </cfif>                        


                    </cfloop>                
    
                    <tr>
                        <td colspan="7" align="right">
                            <cfinput type="hidden" name="FormAction" value="#FormAction#">
                            <cfinput type="hidden" name="FormCompleteAction" value="#FormCompleteAction#">
                            <cfinput type="button" name="Submit" value="Complete">
                        </td> 
                    </tr>
                </table>
                            
            </cfform>
        </div>    
    </cfoutput>
    
</cffunction>